package com.ssyc.student.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.netease.nim.uikit.api.NimUIKit;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.student.R;
import com.ssyc.student.bean.StTeamInfo;

import java.util.List;

/**
 * 学生端--群聊天进入群的资料适配器
 * Created by Administrator on 2018/5/23 0023.
 */

public class StTeamRvAdapter extends BaseQuickAdapter<StTeamInfo.ListBean, BaseViewHolder> {
    private Context context;

    public StTeamRvAdapter(Context context, int layoutResId, @Nullable List<StTeamInfo.ListBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, StTeamInfo.ListBean item) {


        //头像
        RoundedImageView ivHead = helper.getView(R.id.iv_head);
        ImageUtil.displayImage(context, ivHead, item.getHeadimg(), R.drawable.defaultimage);

        //姓名
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.getName());
        //电话号码,对中间五位进行*号替换然后显示
        TextView tvPhone = helper.getView(R.id.tv_phone);
        String phone = item.getUser_id();
        if (!TextUtils.isEmpty(phone)) {
            String str = "*****";
            StringBuilder sb = new StringBuilder(phone);
            sb.replace(3, 8, str);
            tvPhone.setText(sb.toString());
        }

        //显示的类型,student或者teacher
        TextView tvType = helper.getView(R.id.tv_type);

        //角色
        if ("0".equals(item.getRole())) {
            //学生
            tvType.setText("student");
            tvType.setBackgroundResource(R.drawable.st_friend_student);
        } else if ("1".equals(item.getRole())) {
            //家长
            tvType.setText("parent");
            tvType.setBackgroundResource(R.drawable.base_friend_parent);
        }else if ("2".equals(item.getRole())) {
            //老师
            tvType.setText("teacher");
            tvType.setBackgroundResource(R.drawable.st_friend_teacher);
        } else if ("3".equals(item.getRole())) {
            //校长
            tvType.setText("principal");
            tvType.setBackgroundResource(R.drawable.st_friend_principal);
        }

        //点击事件
        ivHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //头像的点击事件,跳转到个人资料界面
                // TODO: 2018/5/15 0015
            }
        });

        //整个条目
        LinearLayout llOut = helper.getView(R.id.ll_out);
        llOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //条目的点击事件,跳转到单聊界面
                NimUIKit.startP2PSession(context, item.getUser_id() + item.getRole());
            }
        });

    }
}
